package com.freight.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.user.dto.CompanyDto;
import com.freight.user.service.ICompanyVoService;
import com.freight.user.vo.AppointCompanyInfoVo;
import com.freight.user.vo.CompanyDetailInfoVo;
import com.freight.user.vo.CompanyInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "订单预约管理接口")
@RequestMapping("/freight/companyInfoVo")
@Transactional
public class UserCompanyVoController {

    @Autowired
    private ICompanyVoService iCompanyVoService;

    @RequestMapping(value = "/getAppointCompanyInfoByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<AppointCompanyInfoVo> getAppointCompanyInfoByUserId(Long userId) {
        AppointCompanyInfoVo CompanyInfoVo = iCompanyVoService.getAppointCompanyInfoVoByUserId(userId);
        return new ResultUtil<AppointCompanyInfoVo>().setData(CompanyInfoVo);
    }

    @RequestMapping(value = "/getAppointCompanyInfoByUserIds", method = RequestMethod.GET)
    @ApiOperation(value = "批量获取公司预约信息")
    public Result<List<AppointCompanyInfoVo>> getAppointCompanyInfoByUserIds(Long[] userId) {
        List<AppointCompanyInfoVo> appointCompanyInfoVos = iCompanyVoService.getAppointCompanyInfoVoByUserIds(userId);
        return new ResultUtil<List<AppointCompanyInfoVo>>().setData(appointCompanyInfoVos);
    }

    @RequestMapping(value = "/getCompanyInfo", method = RequestMethod.GET)
    @ApiOperation(value = "获取货主信息")
    public Result<IPage<CompanyDetailInfoVo>> getCompanyInfo(PageVo page, CompanyDto companyDto) {
        Page<CompanyDetailInfoVo> companyInfoVos = iCompanyVoService.getCompanyInfoVo(PageUtil.initMpPage(page),companyDto);
        return new ResultUtil<IPage<CompanyDetailInfoVo>>().setData(companyInfoVos);
    }

    @RequestMapping(value = "/getCompanyInfoByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "获取公司信息")
    public Result<CompanyInfoVo> getCompanyInfoByUserIds(Long userId) {
        CompanyInfoVo CompanyInfoVo = iCompanyVoService.getCompanyInfoVoByUserId(userId);
        return new ResultUtil<CompanyInfoVo>().setData(CompanyInfoVo);
    }

    @RequestMapping(value = "/getCompanyInfoByUserIds", method = RequestMethod.GET)
    @ApiOperation(value = "获取注册公司信息")
    public Result<List<CompanyInfoVo>> getCompanyInfoByUserIds(Long[] userIds) {
        List<CompanyInfoVo> companyInfoVos = iCompanyVoService.getRegistCompanyInfoVo(userIds);
        return new ResultUtil<List<CompanyInfoVo>>().setData(companyInfoVos);
    }

}
